package com.lhys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lhys.mapper.AssetStorageMapper;
import com.lhys.pojo.AssetStorage;
import com.lhys.service.AssetStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 资产_存放处表 服务实现类
 * </p>
 *
 * @author 小七
 * @since 2021-05-06
 */
@Service
public class AssetStorageServiceImpl implements AssetStorageService {
    @Autowired
    private AssetStorageMapper assetStorageMapper;

    @Override
    @Transactional
    public Boolean saveAssetStorage(AssetStorage assetStorage) {
        try {
            if (assetStorage.getId() == null) {
                assetStorage.setCreateTime(new Date());
                return assetStorageMapper.addAssetStorage(assetStorage) > 0;
            }
            return assetStorageMapper.updateAssetStorage(assetStorage) > 0;
        } catch (Exception e) {
            System.out.println("重复添加");
            return null;
        }
    }

    @Override
    @Transactional
    public Boolean delAssetStorageById(Integer id) {
        return assetStorageMapper.delAssetStorage(id) > 0;
    }

    @Override
    public AssetStorage getAssetStorageById(Integer id) {
        return assetStorageMapper.getAssetStorageById(id);
    }

    @Override
    public PageInfo<AssetStorage> getAssetStorageList(AssetStorage assetStorage, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AssetStorage> list = assetStorageMapper.getAssetStorageByStatusAndTitleOrRemarkList(assetStorage);
        PageInfo<AssetStorage> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public AssetStorage getAssetStorageByCode(String code) {

        return assetStorageMapper.getAssetStorageByCode(code);
    }

    @Override
    public AssetStorage getAssetStorageByTitle(String title) {
        return assetStorageMapper.getAssetStorageByTitle(title);
    }
}